package com.example.abc.common;

import org.springframework.http.HttpStatus;

/**
 * Created by Peter on 2018/1/26.
 */
public class RestResponse<T> {
    private int status = HttpStatus.OK.value();
    private String message = "ok";
    private T data;


    private RestResponse(){

    }
    private RestResponse(T data){
        this.data = data;
    }
    public static RestResponse getSuccessResponse(){
        return new RestResponse();
    }
    public static RestResponse getSuccessResponse(Object data){
        return new RestResponse(data);
    }
    public static RestResponse getClientErrorResponse(String msg){
        RestResponse restResponse= new RestResponse();
        restResponse.setStatus(HttpStatus.BAD_REQUEST.value());
        restResponse.setMessage(msg);

        return restResponse;
    }
    public static RestResponse getServerErrorResponse(String msg){
        RestResponse restResponse= new RestResponse();
        restResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        restResponse.setMessage(msg);

        return restResponse;
    }

    public static RestResponse getServerErrorResponse(String msg,int status){
        RestResponse restResponse= new RestResponse();
        restResponse.setStatus(status);
        restResponse.setMessage(msg);

        return restResponse;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
